package com.server.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.server.authority.Login;
import com.server.common.base.ProjectInfor;
import com.server.common.base.SessionData;
import com.server.service.IAmountService;
import com.server.web.DataVector;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;
import com.server.web.RequestInput;
import com.server.web.SessionUtil;

@Controller
@RequestMapping("amount")
public class AmountController {

	@Autowired
	private IAmountService amountService;
	
	
	@RequestMapping("")
	public ModelAndView orgPage(){
		ModelAndView mv = new ModelAndView("userCenter/amount/amount_new");
		mv.addObject("projectName",ProjectInfor.PLATFORM_NAME);
		mv.addObject("rootPath",ProjectInfor.ROOT_PATH);
		return mv;
	}
	
	@RequestMapping("listPage/{type}")
	public ModelAndView listPage(HttpServletRequest request,@PathVariable Integer type){
		ModelAndView mv = new ModelAndView("userCenter/amount/amountList");
		mv.addObject("projectName",ProjectInfor.PLATFORM_NAME);
		mv.addObject("rootPath",ProjectInfor.ROOT_PATH);
		mv.addObject("type",type);
		return mv;
	}
	
	
	@RequestMapping("list/{type}")
	public void list(HttpServletRequest request,
			HttpServletResponse response,@PathVariable Integer type){
		String cardId = SessionUtil.getStringAttri(request, SessionData.cardIdKey);
		DataVector<Map<String, Object>> listData = amountService.getList(new RequestInput(request),cardId,type); 
		OutputUtil.returnString(response, JSONSerielizer.toJson(listData.getList(), null, null));
	}
}
